// pages/zhuce/zhuce.js
// var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
// var qqmapsdk;
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    select: false, //主营项目选项
    xiangmlist: [],
    tihuoWay: '休闲零食', //主营项目
    tihuoWaynum: '', //主营项目编号
    changName: '', // 厂家名称
    imgURL: '', // 厂家logo
    region: [], // 厂家大地址
    xiangxdiz: '', // 厂家小地址
    zhizhao1: '', //营业执照1
    zhizhao2: '', //营业执照2
    zhizhao3: '', //营业执照3
    xinyongma: '', //信用代码
    kefuphone: '', //客服电话
    yingyeperson: '', //营业人
    yingyephone: '', //营业人电话
    yingyepersoncode: '', //营业人身份证号
    zhengcard: '', //身份证正面
    fancard: '', //身份证反面
    latitude: '',
    longitude: '',

    userid: '',
    yanzhengma: '',
    yzmTime: 60,








    showModal: false,
    shenglist: [], //省列表
    shengid: '', //选择的省ID
    shengindex: '',
    shilist: [], //市列表
    shiid: '', //选择的市ID
    shiindex: '',
    xian: [], //县列表
    xianid: '', //选择的县ID
    xianindex: '',
    titleindex: 1, //现在在选择那个位置
    fixobj: ''

  },
  // 选择市区
  bindRegionChange: function () {
    let that = this
    that.setData({
      showModal: true
    })
    setTimeout(function () {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    that.getsheng()
  },
  // 点击省的表头
  tapsheng() {
    let that = this
    setTimeout(function () {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    that.setData({
      shilist: [],
      shiindex: '',
      shiid: '', //选择的市ID
      xian: [],
      xianid: '', //选择的县ID
      xianindex: '',
      titleindex: 1
    })
    that.getsheng()
  },
  // 点击省份
  fixsheng(e) {
    let that = this
    setTimeout(function () {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    that.setData({
      shengid: e.currentTarget.dataset.shengid,
      shengindex: e.currentTarget.dataset.index,
      titleindex: 2
    })
    // that.getshi()
    that.tapshi()
  },
  // 点击市标头
  tapshi() {
    let that = this
    if (!that.data.shengindex) {
      wx.showToast({
        title: '请先选择省！',
        icon: 'none'
      })
      return
    }
    setTimeout(function () {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    that.setData({
      xian: [],
      xianid: '', //选择的县ID
      xianindex: '',
      titleindex: 2
    })
    that.getshi()
  },
  // 点击市
  fixshi(e) {
    let that = this
    setTimeout(function () {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    that.setData({
      shiid: e.currentTarget.dataset.shengid,
      shiindex: e.currentTarget.dataset.index,
      titleindex: 3
    })
    that.getxian()
  },
  // 点击城市名
  fixxian(e) {
    let that = this
    let fixobj = {
      province: that.data.shenglist[that.data.shengindex - 1],
      city: that.data.shilist[that.data.shiindex - 1],
      county: that.data.xian[e.currentTarget.dataset.index - 1],
      townId: e.currentTarget.dataset.shengid
    }
    that.setData({
      xianid: e.currentTarget.dataset.shengid,
      xianindex: e.currentTarget.dataset.index,
      fixobj: fixobj
    })
  },
  // 选择后确定
  fixandsure() {
    let that = this
    if (!that.data.xianindex) {
      wx.showToast({
        title: '请选择县区后，再点击确定。',
        icon: 'none'
      })
      return
    }
    that.setData({
      showModal: false
    })
  },
  // 获取省列表
  getsheng() {
    let that = this
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "getProvinceInfo"
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        console.log(res)
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        if (res.data.result == 1) {
          setTimeout(function () {
            wx.hideLoading()
          }, 0)
          setTimeout(function () {
            wx.showToast({
              title: res.data.resultNote,
              icon: 'none',
              duration: 1500
            })
          }, 0)
        } else {
          let shenglist = res.data.provinceList
          for (var index in res.data.provinceList) {
            res.data.provinceList[index].actives = false
          }
          that.setData({
            shenglist: shenglist
          })
          setTimeout(function () {
            wx.hideLoading()
          }, 0)
        }

      }
    });
  },
  getshi() {
    let that = this
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "getCityInfo",
        provinceId: that.data.shengid
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        console.log(res)
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        if (res.data.result == 1) {
          setTimeout(function () {
            wx.hideLoading()
          }, 0)
          setTimeout(function () {
            wx.showToast({
              title: res.data.resultNote,
              icon: 'none',
              duration: 1500
            })
          }, 0)
        } else {
          let cityList = res.data.cityList
          for (var index in res.data.cityList) {
            res.data.cityList[index].actives = false
          }
          that.setData({
            shilist: cityList
          })
          setTimeout(function () {
            wx.hideLoading()
          }, 0)
        }
      }
    });
  },
  getxian() {
    let that = this
    if (!that.data.shiindex) {
      wx.showToast({
        title: '请先选择市',
        icon: 'none'
      })
      return
    }
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "getTownInfo",
        cityId: that.data.shiid
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        console.log(res)
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        if (res.data.result == 1) {
          setTimeout(function () {
            wx.hideLoading()
          }, 0)
          setTimeout(function () {
            wx.showToast({
              title: res.data.resultNote,
              icon: 'none',
              duration: 1500
            })
          }, 0)
        } else {
          let townList = res.data.townList
          for (var index in townList) {
            townList[index].actives = false
            for (let j in that.data.tlist) {
              if (that.data.tlist[j] == townList[index].townId) {
                townList[index].actives = true
              }
            }
          }
          that.setData({
            xian: townList,
            titleindex: 3
          })
          setTimeout(function () {
            wx.hideLoading()
          }, 0)
        }
      }
    });
  },
  close_mask: function () {
    this.setData({
      showModal: false
    })
  },
























  // 发送验证码
  fasongyzm() {
    let that = this
    var telStr = /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/;
    var inputStr = that.data.yingyephone
    if (!(telStr.test(inputStr))) {
      wx.showToast({
        title: '手机号码输入不规范',
        icon: 'none',
        duration: 1500
      })
      return
    }
    that.setData({
      yzmTime: 59
    })
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "phoneMSCode",
        userPhone: inputStr
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        console.log(res)
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        setTimeout(function () {
          wx.showToast({
            title: res.data.resultNote,
            icon: 'none',
            duration: 2000
          })
        }, 0)
      }
    });
    var interval = setInterval(function timestampToTime() {
      var date = that.data.yzmTime
      if (date <= 1) {
        that.setData({
          yzmTime: 60
        })
        clearInterval(interval)
      } else {
        date--
        that.setData({
          yzmTime: date
        })
        // console.log(date)
      }
    }, 1000);
  },
  // 验证码
  yingyeyanzheng(e) {
    let that = this
    // console.log(e.detail.value)
    that.setData({
      yanzhengma: e.detail.value
    })
  },
  // 提交注册
  lijizhuce() {
    let that = this;
    var format = /^(([1][1-5])|([2][1-3])|([3][1-7])|([4][1-6])|([5][0-4])|([6][1-5])|([7][1])|([8][1-2]))\d{4}(([1][9]\d{2})|([2]\d{3}))(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1]))\d{3}[0-9xX]$/
    
    if (!that.data.changName) {
      setTimeout(function () {
        wx.showToast({
          title: '请输入厂家名称',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.imgURL) {
      setTimeout(function () {
        wx.showToast({
          title: '请上传厂家logo',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.xianid) {
      setTimeout(function () {
        wx.showToast({
          title: '请选择厂家地址',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.xiangxdiz) {
      setTimeout(function () {
        wx.showToast({
          title: '请输入厂家地址详细地址',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.zhizhao1 && !that.data.zhizhao2 && !that.data.zhizhao3) {
      setTimeout(function () {
        wx.showToast({
          title: '请上传企业执照（至少一张）',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.xinyongma) {
      setTimeout(function () {
        wx.showToast({
          title: '请填写唯一社会信用代码',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (that.data.xinyongma.length != 18) {
      setTimeout(function () {
        wx.showToast({
          title: '唯一社会信用代码有误！',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.kefuphone) {
      setTimeout(function () {
        wx.showToast({
          title: '请填写客服电话',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.yingyeperson) {
      setTimeout(function () {
        wx.showToast({
          title: '请填写姓名',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.yingyephone) {
      setTimeout(function () {
        wx.showToast({
          title: '请填写联系电话',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.yanzhengma) {
      setTimeout(function () {
        wx.showToast({
          title: '请填写验证码',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.yingyepersoncode) {
      setTimeout(function () {
        wx.showToast({
          title: '请填写身份证号',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!(format.test(that.data.yingyepersoncode))) {
      setTimeout(function () {
        wx.showToast({
          title: '身份证信息有误！',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.zhengcard) {
      setTimeout(function () {
        wx.showToast({
          title: '请上传身份证人像面',
          icon: 'none'
        })
      }, 0)
      return
    }
    if (!that.data.fancard) {
      setTimeout(function () {
        wx.showToast({
          title: '请上传身份证国徽面',
          icon: 'none'
        })
      }, 0)
      return
    }
    // 上传企业执照

    let shopImgs = []
    if (that.data.zhizhao1) {
      shopImgs.push({
        img: that.data.zhizhao1
      })

    }
    if (that.data.zhizhao2) {
      shopImgs.push({
        img: that.data.zhizhao2
      })

    }
    if (that.data.zhizhao3) {
      shopImgs.push({
        img: that.data.zhizhao3
      })
    }
    let busiLicImg = [{
      img: that.data.zhengcard
    },
    {
      img: that.data.fancard
    }
    ]
    setTimeout(function () {
      wx.showLoading({
        title: '提交中',
      })
    }, 0)
    // 提交信息
    wx.request({
      url: app.globalData.myurl,
      method: 'POST',
      data: {
        cmd: "sApplication",
        userId: that.data.userid,
        realName: that.data.yingyeperson,
        idCardNum: that.data.yingyepersoncode,
        telephone: that.data.yingyephone,
        shopPhone: that.data.kefuphone,
        smsCode: that.data.yanzhengma,
        shopName: that.data.changName,
        shopTypeId: that.data.tihuoWaynum,
        lng: '',
        lat: '',
        detailedAddr: that.data.xiangxdiz,
        creditCode: that.data.xinyongma,
        // 照片****************************************
        shopImgs: JSON.stringify(shopImgs),
        busiLicImg: JSON.stringify(busiLicImg),
        // logo
        shoplogo: that.data.imgURL,
        province: that.data.fixobj.province.province,
        city: that.data.fixobj.city.city,
        town: that.data.fixobj.county.town,
        supInfo: '',
        townId: that.data.xianid,
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        console.log(res)
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        setTimeout(function () {
          wx.hideLoading()
        }, 0)
        setTimeout(function () {
          wx.showToast({
            title: res.data.resultNote,
            icon: 'none',
            duration: 1000
          })
        }, 0)
        if (res.data.result == 1) {
          return
        } else {
          if (wx.getStorageSync('userId')) {
            wx.setStorageSync("phone", that.data.yingyephone);
            setTimeout(function () {
              wx.switchTab({
                url: '/pages/tabBar/index/index',
              })
            }, 1000)
          } else {
            setTimeout(function () {
              wx.navigateTo({
                url: '/pages/login/login',
              })
            }, 1000)
          }
        }
      }
    });
  },
  // 获取项目列表
  getfenllist() {
    let that = this
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "shopTypeList"
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        that.setData({
          xiangmlist: res.data.shopTypeList,
          tihuoWay: res.data.shopTypeList[0].shopTypeName,
          tihuoWaynum: res.data.shopTypeList[0].shopTypeId
        })
        setTimeout(function () {
          wx.hideLoading()
        }, 0)
      }
    });
  },

  // 厂家名称
  changname(e) {
    let that = this
    // console.log(e.detail.value)
    that.setData({
      changName: e.detail.value
    })
  },
  // 厂家详细地址
  xiangxsite(e) {
    let that = this
    // console.log(e.detail.value)
    that.setData({
      xiangxdiz: e.detail.value
    })
  },
  //信用代码
  xinyongdm(e) {
    let that = this
    console.log(e.detail.value)
    let val = e.detail.value
    let codeReg = new RegExp("[A-Za-z0-9]+"); //正则 英文+数字；
    if (val.length != 18){
      wx.showToast({
        title: '请输入正确的信用代码',
        icon: 'none',

      })
    }

    if (codeReg.test(val)) {
      that.setData({
        xinyongma: val
      })
    } else {

      wx.showToast({
        title: '请输入正确的信用代码',
        icon: 'none',

      })
      that.setData({
        xinyongma: ''
      })
    }

  },
  onBlur(e) {
    console.log(e)
    let val = e.detail.value
    let codeReg = new RegExp("[A-Za-z0-9]+"), len = val.length, str = '';//正则 英文+数字；
    for (var i = 0; i < len; i++) {
      if (codeReg.test(val[i])) {
        str += val[i];
      }
    }
    console.log(str)
    this.setData({
      xinyongma: str
    })


  },
  //信用代码
  kefuphone(e) {
    let that = this
    // console.log(e.detail.value)
    that.setData({
      kefuphone: e.detail.value
    })
  },
  //营业人
  yingyeperson(e) {
    let that = this
    // console.log(e.detail.value)
    that.setData({
      yingyeperson: e.detail.value
    })
  },
  //营业phone
  yingyephone(e) {
    let that = this
    // console.log(e.detail.value)
    that.setData({
      yingyephone: e.detail.value
    })
  },
  yingyepersoncode(e) {
    let that = this
    // console.log(e.detail.value)
    that.setData({
      yingyepersoncode: e.detail.value
    })
  },
  // 上传厂家营业执照
  upzhizhao1() {
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths[0]
        if (res.tempFiles[0].size > 1000000) {
          wx.showToast({
            title: '图片大于1M，请重新选择！',
            icon: 'none'
          })
          return
        } else {
          setTimeout(function () {
            wx.showLoading({
              title: '上传中',
              mask: true
            })
          }, 0)
          wx.request({
            url: app.globalData.myurl,
            method: 'POST',
            data: {
              cmd: "uploadImg",
              imgFile: wx.getFileSystemManager().readFileSync(tempFilePaths, "base64"),
            },
            header: {
              "content-type": "application/x-www-form-urlencoded",
              "token": wx.getStorageSync('token')
            },
            success(res) {
              if (res.data.zjstate == 1) {
                setTimeout(function () {
                  wx.hideLoading()
                  wx.stopPullDownRefresh() //停止下拉刷新
                }, 0)
                setTimeout(function () {
                  wx.showModal({
                    title: '您的账号已在其他设备登录，请重新登录！',
                    showCancel: false, //是否显示取消按钮false去掉取消按钮
                    success: function (res) {
                      if (res.confirm) {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      } else {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      }
                    }
                  })
                }, 0)
                return
              }
              that.setData({
                zhizhao1: res.data.imgUrl
              })
              setTimeout(function () {
                wx.hideLoading()
              }, 0)
              setTimeout(function () {
                wx.showToast({
                  title: res.data.resultNote,
                  icon: 'none',
                  duration: 1500
                })
              }, 0)
            }
          });
        }
      }
    })
  },
  // 上传厂家营业执照
  upzhizhao2() {
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths[0]
        if (res.tempFiles[0].size > 1000000) {
          wx.showToast({
            title: '图片大于1M，请重新选择！',
            icon: 'none'
          })
          return
        } else {
          setTimeout(function () {
            wx.showLoading({
              title: '上传中',
              mask: true
            })
          }, 0)
          wx.request({
            url: app.globalData.myurl,
            method: 'POST',
            data: {
              cmd: "uploadImg",
              imgFile: wx.getFileSystemManager().readFileSync(tempFilePaths, "base64"),
            },
            header: {
              "content-type": "application/x-www-form-urlencoded",
              "token": wx.getStorageSync('token')
            },
            success(res) {
              if (res.data.zjstate == 1) {
                setTimeout(function () {
                  wx.hideLoading()
                  wx.stopPullDownRefresh() //停止下拉刷新
                }, 0)
                setTimeout(function () {
                  wx.showModal({
                    title: '您的账号已在其他设备登录，请重新登录！',
                    showCancel: false, //是否显示取消按钮false去掉取消按钮
                    success: function (res) {
                      if (res.confirm) {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      } else {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      }
                    }
                  })
                }, 0)
                return
              }
              that.setData({
                zhizhao2: res.data.imgUrl
              })
              setTimeout(function () {
                wx.hideLoading()
              }, 0)
              setTimeout(function () {
                wx.showToast({
                  title: res.data.resultNote,
                  icon: 'none',
                  duration: 1500
                })
              }, 0)
            }
          });
        }
      }
    })
  },
  // 上传厂家营业执照
  upzhizhao3() {
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths[0]
        if (res.tempFiles[0].size > 1000000) {
          wx.showToast({
            title: '图片大于1M，请重新选择！',
            icon: 'none'
          })
          return
        } else {
          setTimeout(function () {
            wx.showLoading({
              title: '上传中',
              mask: true
            })
          }, 0)
          wx.request({
            url: app.globalData.myurl,
            method: 'POST',
            data: {
              cmd: "uploadImg",
              imgFile: wx.getFileSystemManager().readFileSync(tempFilePaths, "base64"),
            },
            header: {
              "content-type": "application/x-www-form-urlencoded",
              "token": wx.getStorageSync('token')
            },
            success(res) {
              if (res.data.zjstate == 1) {
                setTimeout(function () {
                  wx.hideLoading()
                  wx.stopPullDownRefresh() //停止下拉刷新
                }, 0)
                setTimeout(function () {
                  wx.showModal({
                    title: '您的账号已在其他设备登录，请重新登录！',
                    showCancel: false, //是否显示取消按钮false去掉取消按钮
                    success: function (res) {
                      if (res.confirm) {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      } else {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      }
                    }
                  })
                }, 0)
                return
              }
              that.setData({
                zhizhao3: res.data.imgUrl
              })
              setTimeout(function () {
                wx.hideLoading()
              }, 0)
              setTimeout(function () {
                wx.showToast({
                  title: res.data.resultNote,
                  icon: 'none',
                  duration: 1500
                })
              }, 0)
            }
          });
        }
      }
    })
  },
  // 上传厂家logo
  uplogos() {
    let that = this
    wx.navigateTo({
      url: '/pages/setting/page/cropper/cropper',
    })
  },
  // 上传身份证正面
  upcardz() {
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        console.log(res)
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths[0]
        if (res.tempFiles[0].size > 1000000) {
          wx.showToast({
            title: '图片大于1M，请重新选择！',
            icon: 'none'
          })
          return
        } else {
          setTimeout(function () {
            wx.showLoading({
              title: '上传中',
              mask: true
            })
          }, 0)
          wx.request({
            url: app.globalData.myurl,
            method: 'POST',
            data: {
              cmd: "uploadImg",
              imgFile: wx.getFileSystemManager().readFileSync(tempFilePaths, "base64"),
            },
            header: {
              "content-type": "application/x-www-form-urlencoded",
              "token": wx.getStorageSync('token')
            },
            success(res) {
              if (res.data.zjstate == 1) {
                setTimeout(function () {
                  wx.hideLoading()
                  wx.stopPullDownRefresh() //停止下拉刷新
                }, 0)
                setTimeout(function () {
                  wx.showModal({
                    title: '您的账号已在其他设备登录，请重新登录！',
                    showCancel: false, //是否显示取消按钮false去掉取消按钮
                    success: function (res) {
                      if (res.confirm) {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      } else {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      }
                    }
                  })
                }, 0)
                return
              }
              that.setData({
                zhengcard: res.data.imgUrl
              })
              setTimeout(function () {
                wx.hideLoading()
              }, 0)
              setTimeout(function () {
                wx.showToast({
                  title: res.data.resultNote,
                  icon: 'none',
                  duration: 1500
                })
              }, 0)
            }
          });
        }
      }
    })
  },
  // 上传身份证反面
  upcardf() {
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths[0]
        if (res.tempFiles[0].size > 1000000) {
          wx.showToast({
            title: '图片大于1M，请重新选择！',
            icon: 'none'
          })
          return
        } else {
          setTimeout(function () {
            wx.showLoading({
              title: '上传中',
              mask: true
            })
          }, 0)
          wx.request({
            url: app.globalData.myurl,
            method: 'POST',
            data: {
              cmd: "uploadImg",
              imgFile: wx.getFileSystemManager().readFileSync(tempFilePaths, "base64"),
            },
            header: {
              "content-type": "application/x-www-form-urlencoded",
              "token": wx.getStorageSync('token')
            },
            success(res) {
              if (res.data.zjstate == 1) {
                setTimeout(function () {
                  wx.hideLoading()
                  wx.stopPullDownRefresh() //停止下拉刷新
                }, 0)
                setTimeout(function () {
                  wx.showModal({
                    title: '您的账号已在其他设备登录，请重新登录！',
                    showCancel: false, //是否显示取消按钮false去掉取消按钮
                    success: function (res) {
                      if (res.confirm) {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      } else {
                        wx.clearStorageSync()
                        wx.reLaunch({
                          url: '/pages/login/login',
                        })
                      }
                    }
                  })
                }, 0)
                return
              }
              that.setData({
                fancard: res.data.imgUrl
              })
              setTimeout(function () {
                wx.hideLoading()
              }, 0)
              setTimeout(function () {
                wx.showToast({
                  title: res.data.resultNote,
                  icon: 'none',
                  duration: 1500
                })
              }, 0)
            }
          });
        }
      }
    })
  },

  // 弹出下拉
  bindShowMsg() {
    this.setData({
      select: !this.data.select
    })
  },
  // 选择下拉值
  mySelect(e) {
    var name = e.currentTarget.dataset.name
    let num = e.currentTarget.dataset.num
    this.setData({
      tihuoWay: name,
      tihuoWaynum: num,
      select: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let that = this
    that.setData({
      userid: options.userid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    setTimeout(function () {
      wx.showLoading({
        title: '加载中'
      })
    }, 0)
    that.getfenllist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})


























// 选择市区
// bindRegionChange: function() {
//   qqmapsdk = new QQMapWX({
//     key: 'JZPBZ-U5CWU-WAMVJ-2SCHB-AQDY5-LKF6U' //腾讯地图key
//   });
//   let that = this
//   wx.chooseLocation({
//     success: function (res) {
//       // console.log(res)
//       qqmapsdk.reverseGeocoder({
//         location: {
//           latitude: res.latitude,
//           longitude: res.longitude
//         },
//         success: function (ress) {
//           // console.log(ress.result.address_component)
//           that.setData({
//             latitude: res.latitude,
//             longitude: res.longitude,
//             region: [ress.result.address_component.province, ress.result.address_component.city, ress.result.address_component.district]
//           })
//         },
//         fail: function (error) {
//           console.error(error);
//         },
//       })
//     }
//   })
// },